package com.sdcs.server.controller;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams;
import org.displaytag.tags.TableTagParameters;
import org.displaytag.util.ParamEncoder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sdcs.server.comm.Tool;
import com.sdcs.server.model.*;
import com.sdcs.server.service.*;

@Controller
public class ServerController {
	@Autowired
	private TeacherService teacherService;
	
	@Autowired
	private StudentService studentService;
	
	@Autowired
	private DiscussService discussService;
	
	@Autowired
	private AttendanceService attendanceService;
	
	@Autowired
	private CourseService courseService;
	
	@Autowired
	private ResourceService resourceService;
	
	@Autowired
	private HomeworkService homeworkService;
	
	@Autowired
	private ReplyService replyService;
	
	@RequestMapping(value = "login.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void login(String name, String password, String type, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		if("2".equals(type)){
//			学生
			Student student = studentService.getStudent(name, password);
			if (student != null) {
				request.getSession().setAttribute("sid", student.getStudent_id());
				request.getSession().setAttribute("screen_name", student.getStudent_name());
				request.getSession().setAttribute("type", "2");
				request.getRequestDispatcher("/index.jsp").forward(request, response);
				return ;
			}
		} else {
//			教师
			Teacher teacher = teacherService.login(name, password);
			if (teacher != null) {
				request.getSession().setAttribute("admin", teacher.getTeacher_id());
				request.getSession().setAttribute("screen_name", teacher.getTeacher_screen_name());
				request.getSession().setAttribute("sid", teacher.getTeacher_id());
				request.getSession().setAttribute("type", "1");
				request.getRequestDispatcher("/index.jsp").forward(request, response);
				return ;
			}
		}
		 
		request.setAttribute("s", "0");
		request.getRequestDispatcher("/login.jsp").forward(request, response);
	}
	
	@RequestMapping(value = "logout.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getSession().invalidate();
		request.getRequestDispatcher("/login.jsp").forward(request, response);
	}
	
	@RequestMapping(value = "updatePassword.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void updatePassword(String admin, String oldPassword, String newPassword, String sid, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		boolean is_admin = admin != null ? true : false;
		Teacher teacher = null;
		
		if (is_admin) {
			teacher = teacherService.getById(sid);
			if(oldPassword.equals(teacher.getPassword().trim())){
				teacher.setPassword(newPassword);
				teacherService.update(teacher) ;
			}else{
				request.setAttribute("result", "0");
				request.getRequestDispatcher("/updatePassword.jsp").forward(request, response);
				return ;
			}
		}
		
		request.setAttribute("result", "1");
		request.getRequestDispatcher("/updatePassword.jsp").forward(request, response);
	}
	
	@RequestMapping(value = "discuss.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void discussDo(String method, String type, String id, String answer, String news_id, String content, String student_name, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if ("list".equals(method)) {
		    if (type != null && type.equals("json")) {
		    	
		    	response.setCharacterEncoding("gb2312");
		    	response.getWriter().write(JSON.toJSON(discussService.getAll(id)).toString());
		    	return ;		    	
			}  else {
				request.setAttribute("list", discussService.getAll(id)); 
				request.getRequestDispatcher("/discuss_list.jsp").forward(request, response);
			}
		    
		} else if ("goUpdate".equals(method)){
			
			request.setAttribute("map", discussService.getObjectById(id)); 
			request.getRequestDispatcher("/discuss_update.jsp").forward(request, response);
   
		} else if ("update".equals(method)){
			
			discussService.update(id, answer) ;  
			request.setAttribute("list", discussService.getAll(news_id)); 
			request.getRequestDispatcher("/discuss_list.jsp").forward(request, response);
			
		} else if ("save".equals(method)) { 
  
			   	Discuss object  = new Discuss(); 
			   	
			   	object.setUsername(student_name);
			   	object.setContent(content);
			   	object.setCourse_id(Integer.valueOf(news_id));
			   	object.setTbl_date(Tool.getNowTime()) ;
			   	object.setAnswer(answer);
			
			   	discussService.save(object);
			   	
			   	response.setCharacterEncoding("utf-8");
	    		response.getWriter().write( "1");
			
		} else if ("del".equals(method)) {
			discussService.delete(id);
			request.setAttribute("list", discussService.getAll(id)); 
			request.getRequestDispatcher("/discuss_list.jsp").forward(request, response);
		}
	}
	
	@RequestMapping(value = "attendance.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void attendanceDo(String method, String id, String student_id, String student_name, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if ("list".equals(method)) {

			request.setAttribute("list", attendanceService.getAll()); 
			request.getRequestDispatcher("/attendance_list.jsp").forward(request, response);
		    
		} else if ("save".equals(method)) { 
		   	Attendance object  = new Attendance(); 
		 
		   	object.setUid(student_id);
		   	object.setUsername(student_name);
		   	object.setTbl_date(Tool.getNowTime());
		
		   	attendanceService.save( object ) ;
		    
		   	response.setCharacterEncoding("utf-8");
		   	response.getWriter().write("1");
			
		} else if ("del".equals(method)) {
			attendanceService.delete(id);
			request.setAttribute("list", attendanceService.getAll()); 
			request.getRequestDispatcher("/attendance_list.jsp").forward(request, response);
		}
		
	}
	
	@RequestMapping(value = "teacher.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void teacherDo(String method, String id, String name, String password, String screen_name, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if ("list".equals(method)) {

			getAllForTeacher(request);
			request.getRequestDispatcher("/teacher_list.jsp").forward(request, response);
			
		} else if ("goEdit".equals(method)) {

			request.setAttribute("map", teacherService.getById(id)) ;
			request.getRequestDispatcher("/teacher_add.jsp").forward(request, response);
			
		} else if ("save".equals(method)) { 
			Teacher teacher = new Teacher();
			
			teacher.setTeacher_name(name);
			teacher.setPassword(password);
			teacher.setTeacher_screen_name(screen_name);

			if(!"".equals(id) ){
//				编辑
				teacher.setTeacher_id(id);
				teacherService.update(teacher); 
				getAllForTeacher(request);
				request.getRequestDispatcher("/teacher_list.jsp").forward(request, response);
			}else{
//				新增
				teacherService.save(teacher);	
				request.setAttribute("s", "0") ; 
				request.getRequestDispatcher("/teacher_add.jsp").forward(request, response);
			}

		} else if ("del".equals(method)) {
			teacherService.delete(id);
			getAllForTeacher(request);
			request.getRequestDispatcher("/teacher_list.jsp").forward(request, response);
		}
	}
	
	private void getAllForTeacher(HttpServletRequest request) { 
		
		int pageNo = 0 ; 
		int start =  0 ;

		String pageName = new ParamEncoder("element").encodeParameterName(TableTagParameters.PARAMETER_PAGE);
		
		if(request.getParameter(pageName) != null && !"".equals(request.getParameter(pageName))) {
			pageNo = Integer.parseInt(request.getParameter(pageName));
		} else {
			pageNo = 1 ;
		}

		start = (pageNo-1) * 5  ;
 
		request.setAttribute("total", teacherService.getTotalCount());
		request.setAttribute("list", teacherService.getAll(start, 5));  
	}
	
	
	@RequestMapping(value = "student.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void studentDo(String method, String student_name, String password, String register, String id, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if ("login".equals(method)) {
			boolean result = studentService.login(student_name, password);
			response.getWriter().print(result);
		
		} else if ("registerAccount".equals(method)) {

			String result = "";
			JSONObject userObject = (JSONObject) JSON.parse(register);
			if (!studentService.isExistsUser(userObject.getString("student_name"))) {
				boolean userResult = studentService.insertUser(new Student(userObject));
				if (userResult) { 
					result = "SUCCESS";
				} else {
					result = "ERROR";
				}
			} else {
				result = "EXISTSUSER";
			}
			response.getWriter().println(result);
				
		} else if ("list".equals(method)) {

			getAllForStudent(request);
			request.getRequestDispatcher("/student_list.jsp").forward(request, response);
	 
		} else if ("del".equals(method)) {
			
			studentService.delete(id);
			getAllForStudent(request);
			request.getRequestDispatcher("/student_list.jsp").forward(request, response);
			
		} else if ("getAll".equals(method)) {
			response.setCharacterEncoding("gb2312");
			JSONArray userArrays = new JSONArray();
			List<Student> list = studentService.getAll();
			for (Student student : list) {
				JSONObject studentObject = new JSONObject();
				studentObject.put("student_id", student.getStudent_id());
				studentObject.put("student_name", student.getStudent_name());
				studentObject.put("student_screen_name", student.getStudent_screen_name());
				studentObject.put("password", student.getPassword());
				studentObject.put("student_phone", student.getStudent_phone());
				studentObject.put("student_address", student.getStudent_address());
				userArrays.add(studentObject);
			}
			JSONObject object = new JSONObject();
			object.put("students", userArrays);
			response.getWriter().write(object.toString());
		}
	}
	
	private void getAllForStudent(HttpServletRequest request) { 
		
		int pageNo = 0 ; 
		int start =  0 ;

		String pageName = new ParamEncoder("element").encodeParameterName(TableTagParameters.PARAMETER_PAGE);
		
		if(request.getParameter(pageName) != null  && !"".equals(request.getParameter(pageName))){
			pageNo = Integer.parseInt( request.getParameter(pageName) );
		}else{
			pageNo = 1 ;
		}

		start = (pageNo-1) * 5 ;
		
		request.setAttribute("total", studentService.getTotalCount());
		request.setAttribute("list", studentService.getAll(start, 5));  
	}
	
	@RequestMapping(value = "course_list.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void courseList(String method, String id, String type, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if (method != null) {
	 		if("del".equals(method)) {
	 	       courseService.delete(id);
	 		} else if("goAdd".equals(method)) {
	 			request.getRequestDispatcher("/course_edit.jsp").forward(request, response);
				return ;
	 		}
	 	}
		 		
	    if (type != null) {
	    	Object object = JSON.toJSON((courseService.getAll()));
	    	response.setCharacterEncoding("gb2312");
	    	response.getWriter().write(object.toString());
	    } else {
      		request.setAttribute("all",  "1" ); 
      		request.setAttribute("list",  courseService.getAll() ); 
	    	request.getRequestDispatcher("/course_list.jsp").forward(request, response);
	    } 
	}
	
	@RequestMapping(value = "course_edit.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void courseDo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(ServletFileUpload.isMultipartContent(request)) {
			   Course info = new Course();
			   
			   DiskFileItemFactory factory = new DiskFileItemFactory();
			   @SuppressWarnings("deprecation")
			   String dir_path =  request.getRealPath("/") ;

			   factory.setRepository(new File( dir_path + "/tmp"));
			   //内存最大占用   
	           factory.setSizeThreshold(1024000);
	           ServletFileUpload sfu = new ServletFileUpload(factory);
	           sfu.setHeaderEncoding("utf-8");
	           
	           //单个文件最大值byte   
	           sfu.setFileSizeMax(102400000);   
	           //所有上传文件的总和最大值byte
	           sfu.setSizeMax(204800000);
	           List<FileItem> items = null;
	           try {
	               items = sfu.parseRequest(request);
	           } catch (SizeLimitExceededException e) {
	               System.out.println("size limit exception!");
	           } catch(Exception e) {
	               e.printStackTrace();
	           }   
	           
	           Iterator<FileItem> iter = items == null ? null : items.iterator();
	           while(iter != null && iter.hasNext()) {
	               FileItem item = (FileItem)iter.next();
	               //简单的表单域   
	               if(item.isFormField()) {
	                   String str = iso2gb(item.getString());
	                   System.out.print("form field:");
	                   System.out.print(item.getFieldName() + "  ");
	                   System.out.print(str);

	                   if("course_name".equals(item.getFieldName())) {
	                	   info.setCourse_name(str);
	                   } else if("course_description".equals(item.getFieldName())) { 
	                	   info.setCourse_description(str);
	                   }
	               }
	           }
	           courseService.save(info);
	           request.setAttribute("s", "0") ;	   
	           request.getRequestDispatcher("/course_edit.jsp").forward(request, response);
		}
	}
	
	@RequestMapping(value = "resource_list.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void resourceList(String method, String id, String type, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if (method != null) {
	 		if("getAllInfo".equals(method)) {
	 			request.setAttribute("list", resourceService.getMyInfo(request.getSession().getAttribute("sid").toString()));
	 			request.getRequestDispatcher("/resource_list.jsp").forward(request, response);
				return; 
	 		} else if ("del".equals(method)) {
	 			resourceService.delete(id);
	 			request.setAttribute("list", resourceService.getMyInfo(request.getSession().getAttribute("sid").toString()));
	 			request.getRequestDispatcher("/resource_list.jsp").forward(request, response);
	 		}
	 	}
	 		
	    if (type != null) {
	      response.setCharacterEncoding("gb2312");
	      response.getWriter().write(JSON.toJSON(resourceService.getAll()).toString());
	    }
	}
	
	@RequestMapping(value = "resource_edit.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void resourceDo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String fileName = "";
		if(ServletFileUpload.isMultipartContent(request)) {
			Resource object = new Resource();
			   
			DiskFileItemFactory factory = new DiskFileItemFactory();   
			@SuppressWarnings("deprecation")
			String dir_path =  request.getRealPath("/") ;

			factory.setRepository(new File( dir_path + "/tmp"));  
			//内存最大占用   
			factory.setSizeThreshold(1024000);   
			ServletFileUpload sfu = new ServletFileUpload(factory);   
			sfu.setHeaderEncoding("utf-8");
	       
			//单个文件最大值byte   
			sfu.setFileSizeMax(102400000);   
			//所有上传文件的总和最大值byte   
			sfu.setSizeMax(204800000);   
			List<FileItem> items = null;   
			try {   
				items = sfu.parseRequest(request);   
			} catch (SizeLimitExceededException e) {   
				System.out.println("size limit exception!");   
			} catch(Exception e) {   
				e.printStackTrace();   
			}
           
			Iterator<FileItem> iter = items == null ? null : items.iterator();
			while(iter != null && iter.hasNext()) {
				FileItem item = (FileItem)iter.next();
				//简单的表单域 
				if(item.isFormField()) {
					String str = iso2gb (item.getString());
					System.out.print("form field:");
					System.out.print(item.getFieldName() + "  ");
					System.out.print(str);
                   
					if("resource_name".equals(item.getFieldName())) {
						object.setResource_name(str);;
					} else if("resource_describe".equals(item.getFieldName())) { 
						object.setResource_describe(str);
					}
                   
					object.setResource_date(Tool.getNowTime());
					if(request.getSession().getAttribute("sid") != null)
						object.setTeacher_id(request.getSession().getAttribute("sid").toString());
				} else if (!item.isFormField()) {   
					//文件域 
					System.out.println("上传文件的名称:" + item.getName());
					if(item.getName().lastIndexOf("/") != -1) {
						fileName = item.getName().substring(item.getName().lastIndexOf("/")+1,item.getName().length());
					} else if(item.getName().lastIndexOf("\\") != -1) {
						fileName = item.getName().substring(item.getName().lastIndexOf("\\")+1,item.getName().length());
					} else {
						fileName = item.getName();
					}
					BufferedInputStream in = new BufferedInputStream(item.getInputStream());   
					//文件存储在工程的upload目录下,这个目录也得存在   
					BufferedOutputStream out = new BufferedOutputStream(   
							new FileOutputStream(new File( dir_path + "/upload/" + fileName)));   
					Streams.copy(in, out, true);   
				}
			}
			object.setResource_path(fileName);
			resourceService.save(object);
			request.setAttribute("s", "0") ;	   
			request.getRequestDispatcher("/resource_edit.jsp").forward(request, response);
		}
	}
	
	@RequestMapping(value = "homework_list.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void homeworkList(String method, String f, String id, String type, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if (method != null) {
			if("del".equals(method)) {
	 	        homeworkService.delete(id);
	 		} else if("getMyInfo".equals(method) ) {
	 			request.setAttribute("list", homeworkService.getMyInfo(request.getSession().getAttribute("sid").toString()));  
	 			request.getRequestDispatcher("/homework_list.jsp").forward(request, response);
				return; 
	 		} else if("getAllInfo".equals(method)) {
	 			request.setAttribute("list", homeworkService.getAll());  
	 			request.getRequestDispatcher("/homework_list.jsp").forward(request, response);
				return; 
	 		}
	 	}
		 		
	    if (type != null) {
	    	response.setCharacterEncoding("gb2312");
	    	response.getWriter().write(JSON.toJSON(homeworkService.getAll()).toString());
	    }
	}
	
	@RequestMapping(value = "homework_edit.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void homeworkDo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(ServletFileUpload.isMultipartContent(request)) {
			Homework object = new Homework();
			DiskFileItemFactory factory = new DiskFileItemFactory();
			@SuppressWarnings("deprecation")
			String dir_path =  request.getRealPath("/");

			factory.setRepository(new File( dir_path + "/tmp"));
			//内存最大占用 
			factory.setSizeThreshold(1024000);
			ServletFileUpload sfu = new ServletFileUpload(factory);
			sfu.setHeaderEncoding("utf-8");
	           
			//单个文件最大值byte
			sfu.setFileSizeMax(102400000);
			//所有上传文件的总和最大值byte
			sfu.setSizeMax(204800000);
			List<FileItem> items = null;
			try {
				items = sfu.parseRequest(request);
			} catch (SizeLimitExceededException e) {
				System.out.println("size limit exception!");
	        } catch (Exception e) {
               e.printStackTrace();
	        }   
	           
			Iterator<FileItem> iter = items==null?null:items.iterator();   
			while(iter != null && iter.hasNext()) {   
				FileItem item = (FileItem)iter.next();   
				//简单的表单域   
				if(item.isFormField()) {   
					String str = iso2gb(item.getString());
					System.out.print("form field:");   
					System.out.print(item.getFieldName() + "  ");   
					System.out.print( str );    
	                   
					if("homework_name".equals(item.getFieldName())){
						object.setHomework_name(str);
					} else if("homework_describe".equals(item.getFieldName())) { 
						object.setHomework_describe(str);
					} 
					object.setHomework_date(Tool.getNowTime());
					if(request.getSession().getAttribute("sid") != null )
						object.setTeacher_id(request.getSession().getAttribute("sid").toString());
               }
           }   
           homeworkService.save(object);
           request.setAttribute("s", "0") ;	   
           request.getRequestDispatcher("/homework_edit.jsp").forward(request, response);
		}
	}
	
	@RequestMapping(value = "reply_edit.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void replyDo(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		String fileName = "";
		if(ServletFileUpload.isMultipartContent(request)) {
			Reply object = new Reply();
			   
			DiskFileItemFactory factory = new DiskFileItemFactory();   
			@SuppressWarnings("deprecation")
			String dir_path =  request.getRealPath("/") ;

			factory.setRepository(new File( dir_path + "/tmp"));  
			//内存最大占用   
			factory.setSizeThreshold(1024000);   
			ServletFileUpload sfu = new ServletFileUpload(factory);   
			sfu.setHeaderEncoding("utf-8");
	           
			//单个文件最大值byte   
			sfu.setFileSizeMax(102400000);   
			//所有上传文件的总和最大值byte   
			sfu.setSizeMax(204800000);   
			List<FileItem> items = null;   
			try {   
				items = sfu.parseRequest(request);   
			} catch (SizeLimitExceededException e) {   
				System.out.println("size limit exception!");   
			} catch(Exception e) {   
				e.printStackTrace();   
			}   
	           
			Iterator<FileItem> iter = items==null?null:items.iterator();   
			while(iter != null && iter.hasNext()) {   
				FileItem item = (FileItem)iter.next();   
				//简单的表单域   
				if(item.isFormField()) {   
					String str = iso2gb(item.getString());
					System.out.print("form field:");   
					System.out.print(item.getFieldName() + "  ");   
					System.out.print( str );    
	                   
					if("reply_name".equals(item.getFieldName())) {
						
					} else if("reply_describe".equals(item.getFieldName())) { 
						object.setReply_describe(str);
					} else if("reply_id".equals(item.getFieldName())) { 
						object.setHomework_id(str);
					} 
					object.setReply_date(Tool.getNowTime());
				} else if (!item.isFormField()) {    
					//文件域   
					System.out.println("上传文件的名称:" + item.getName());
					if(item.getName().lastIndexOf("/") != -1){
						fileName = item.getName().substring(item.getName().lastIndexOf("/") + 1,item.getName().length());
                   	} else if(item.getName().lastIndexOf("\\") != -1){
                   		fileName = item.getName().substring(item.getName().lastIndexOf("\\") + 1,item.getName().length());
                   	} else {
                   		fileName = item.getName();
                   	}
                   BufferedInputStream in = new BufferedInputStream(item.getInputStream());   
                   //文件存储在工程的upload目录下,这个目录也得存在   
                   BufferedOutputStream out = new BufferedOutputStream(   
                            new FileOutputStream(new File( dir_path + "/upload/" + fileName)));   
                   Streams.copy(in, out, true);   
               }   
           }   
	           
           object.setReply_name((String) request.getSession().getAttribute("screen_name"));
    	   object.setReply_path(fileName); 
           replyService.save(object);
           request.setAttribute("s", "0") ;	   
           request.getRequestDispatcher("/reply_edit.jsp").forward(request, response);
		}
	}
	
	@RequestMapping(value = "reply_list.do", method = {RequestMethod.GET, RequestMethod.POST})
	public void replyList(String method, String id, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if (method != null){
	 		if("getMyInfo".equals(method)) {
	 			request.setAttribute("list", replyService.getMyInfo(request.getSession().getAttribute("screen_name").toString()));  
	 			request.getRequestDispatcher("/reply_list.jsp").forward(request, response);
				return; 
	 		} else if("getAllInfoById".equals(method)) {
	 			request.setAttribute("list", replyService.getAllReplyByHomeworkId(id));  
	 			request.getRequestDispatcher("/reply_list.jsp").forward(request, response);
				return; 
	 		}
	 	}
	 		
	}
	
	/**
	 * 
	 *  表单提交乱码解决
	 * @param str
	 * @return
	 */	
	private String iso2gb(String str){
	 
		try {
			return  new  String( str.getBytes("iso-8859-1"),"utf-8" );
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} 
		return null;
	}
}
